import { Routes } from './routers';

/**
 * umi 配置路由设置
 */
const baseRoutes: Routes[] = [
  {
    exact: true,
    path: '/hisSearch',
    title: '查询',
    component: '',
    children: [
      {
        exact: true,
        path: '/hisConsult',
        title: '历史咨询查询',
        component: '',
      },
      {
        exact: true,
        path: '/hisStatistics',
        title: '历史统计咨询查询',
        component: '',
      },
    ],
  },
  {
    exact: true,
    path: 'setting',
    title: '设定',
    component: '',
    children: [
      {
        exact: true,
        path: '/buildSet',
        title: '建物资讯设定',
        component: '@/pages/setting/buildSet',
      },
      {
        exact: true,
        path: '/sensorSet',
        title: '感测器资讯设定',
        component: '@/pages/setting/sensorSet',
      },
      {
        exact: true,
        path: '/sensorTypeSet',
        title: '感测器类别设定',
        component: '@/pages/setting/SensorTypeSet',
      },
      {
        exact: true,
        path: '/systemSet',
        title: '系统资讯设定',
        component: '@/pages/setting/SystemSet',
      },
      {
        hidden: true,
        exact: true,
        path: '/areaMtnSet',
        title: '建物区域资讯设定',
        component: '@/pages/setting/AreaMtnSet',
      },
    ],
  },
  {
    exact: true,
    path: 'plan',
    title: '温湿度平面图',
    component: '',
    children: [
      {
        exact: true,
        path: 'planSet',
        title: '平面图坐标设定',
        component: '',
      },
      {
        exact: true,
        path: 'planView',
        title: '平面图检视',
        component: '',
      },
    ],
  },
  {
    exact: true,
    path: 'authority',
    title: '权限设定',
    component: '',
    children: [
      {
        exact: true,
        path: 'siteAuthority',
        title: 'Site负责人权限设定',
        component: '',
      },
      {
        exact: true,
        path: 'sensorAuthority',
        title: '感测器设定人员权限设定',
        component: '',
      },
      {
        exact: true,
        path: 'viewerAuthority',
        title: '阅览者权限设定',
        component: '',
      },
    ],
  },
  {
    exact: true,
    path: 'immediate',
    title: '即时监视页面',
    component: '',
    children: [
      {
        exact: true,
        path: 'immediateSet',
        title: '即时监视样板管理',
        component: '',
      },
      {
        exact: true,
        path: 'immediateView',
        title: '即时监视检视页面',
        component: '',
      },
    ],
  },
];

const routes: Routes[] = baseRoutes;
const basePath = (list: Routes[]): any => {
  return list.map((item: Routes) => {
    if (item.children && item.children.length) {
      // console.log('存在children', item);
      return basePath(item.children);
    } else {
      // console.log('不存在children', item);
      return { ...item, path: '' };
    }
  });
};

basePath(baseRoutes);
// console.log('路由信息', routes);

export default routes;
